<?php

namespace App\Imports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;

namespace App\Imports;

use App\Models\ProductsApproval;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithStartRow;
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;

class PurchaseImport implements ToModel, WithStartRow,SkipsEmptyRows

{
    /**
     * @param array $row
     *
     * @return \Illuminate\Database\Eloquent\Model|null
     */
    public function model(array $row)
    {
        $user = Auth::user();
        $arr = [
            'supplier_code' => $user->code,
            'product_code' => 0,
            'product_name' => $row[1],
            'generic_name' => $row[2],
            'pinyin_code' => $row[3],
            'specification' => $row[4],
            'unit' => $row[5],
            'origin' => $row[6],
            'manufacturer' => $row[7],
            'barcode' => $row[8],
            'certificate_category_id' => 11,
            'registration_number' => $row[10],
            'dosage_form' => $row[11],
            'package_unit' => $row[12],
            'component_unit' => $row[13],
            'package_specification' => $row[14],
            'component_unit_code' => $row[15],
            'component_specification' => $row[16],
            'preparation_unit_code' => $row[17],
            'business_category_code' => $row[18],
            'preparation_unit' => $row[19],
            'purchase_price' => $row[20],
            'sale_price' =>$row[21],
            'creator_id' => $user->id,
            'create_time' => date("Y-m-d H:i:s", time()),
            'update_time' => date("Y-m-d H:i:s", time()),
        ];
        $productModel = new ProductsApproval();
        $productModel->setProductsApproval($arr);
    }

    /**
     * @return int
     */
    public function startRow(): int
    {
        // 假设数据从第二行开始
        return 2;
    }
}
